package com.atguigu.gmall.order.api;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.order.entity.OrderInfo;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.atguigu.gmall.order.vo.OrderConfirmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/inner/order")
public class OrderInfoApiController {

    @Autowired
    private OrderInfoService orderInfoService ;

    @GetMapping(value = "/trade")
    public Result<OrderConfirmVo> trade() {
        OrderConfirmVo orderConfirmVo = orderInfoService.trade() ;
        return Result.build(orderConfirmVo , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findByOrderId/{orderId}")
    public Result<OrderInfo> findByOrderId(@PathVariable(value = "orderId") String orderId) {
        OrderInfo orderInfo = orderInfoService.findByOrderId(orderId) ;
        return Result.build(orderInfo , ResultCodeEnum.SUCCESS) ;
    }

    @PostMapping(value = "/saveOrderInfo")
    public Result<String> saveOrderInfo(@RequestBody OrderInfo orderInfo) {
        String orderId = orderInfoService.saveOrderInfo(orderInfo) ;
        return Result.build(orderId ,ResultCodeEnum.SUCCESS) ;
    }

}

























